<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    @include('public.h5_head')
    <title>已发布</title>
    <script src="{{ env('CDN_DOMAIN_NAME') }}/js/commonjs/rem.js"></script>
    <link rel="stylesheet" type="text/css" href="{{ env('CDN_DOMAIN_NAME') }}/css/commoncss/common.css"/>
    <link rel="stylesheet" type="text/css" href="{{ env('CDN_DOMAIN_NAME') }}/css/uploadlist.css?v=1.0.6"/>

    <link rel="stylesheet" type="text/css" href="{{ env('CDN_DOMAIN_NAME') }}/css/commoncss/mobiscroll.core-2.5.2.css"  />
	<link rel="stylesheet" type="text/css" href="{{ env('CDN_DOMAIN_NAME') }}/css/commoncss/mobiscroll.android-ics-2.5.2.css"  />
</head>
<script src="{{ env('CDN_DOMAIN_NAME') }}/js/commonjs/4.2.5iscroll.js"></script>
<script src="{{ env('CDN_DOMAIN_NAME') }}/js/app.js"></script>
<script src="{{ env('CDN_DOMAIN_NAME') }}/js/commonjs/common.js"></script>

<script src="{{ env('CDN_DOMAIN_NAME') }}/js/commonjs/mobiscroll.core-2.5.2.js"></script>
<script src="{{ env('CDN_DOMAIN_NAME') }}/js/commonjs/mobiscroll.datetime-2.5.1.js"></script>
<script src="{{ env('CDN_DOMAIN_NAME') }}/js/commonjs/mobiscroll.android-ics-2.5.2.js"></script>
<style>
    .product_size,.produc_color,.yann-color-chose{
        cursor: pointer;
    }
    .yann-color-chose,.circle{
        cursor: pointer;
    }
    .iconfont{
        cursor: pointer;
    }

    /*header a{*/
        /*color: #010101;*/
    /*}*/
</style>
<body>
<div id="box_list">
    <div class="see">
        <form action="" method="get">
            <div class="see_img">
                <div class="see_wrap">
                    <img class="see_pic" src="/img/seek.png" alt="">
                    <input type="text" name="girard" autocomplete="off" autocorrect="off" class="see_name" disabled value="{{ $girard }}" placeholder="搜索">
                </div>
            </div>
            <button class="sousBtn" style="display: none;">搜索</button>
        </form>
    </div>
    <div class="head">
        <a href="/Business/producList"><div class="header_c "><span class="header_d">待发布</span></div></a>
        <div class="header_over"><span class="header_y car">已发布</span></div>
    </div>
    <script>
        var detail_data=[
                @foreach($datas['details'] as $info)
            [{{ $info->id }},{{ $info->produc_id }},'{{ $info->produc_type }}','{{ $info->produc_val }}',{{ $info->pid }}],
                @endforeach
            [-1,'','','']
        ];
        var brand_name=[
                @foreach($brandName as $k=>$v)
            [{{ $k }},'{{ $v }}'],
            @endforeach
        ];
        var company=[
                @foreach($companys as $k=>$v)
            [{{ $k }},'{{ $v }}'],
            @endforeach
        ];
        function getbrandname(id) {
            for(var i=0;i<brand_name.length;i++)
            {
                if(brand_name[i][0]==id  ){
                    return brand_name[i][1]
                }
            }
        }
        function getcompany(id) {
            for(var i=0;i<company.length;i++)
            {
                if(company[i][0]==id  ){
                    return company[i][1]
                }
            }
        }
        function getGood(pro_id,type) {
            var val='{{ env('PRODUCT_DEFAULT_IMG') }}';
            for(var i=0;i<detail_data.length;i++)
            {
                if(detail_data[i][1]==pro_id && detail_data[i][2] == type && parseInt(detail_data[i][4])==0 ){
                    val =  detail_data[i][3];
                    break;
                }
            }
            return val;
        }
        function getGoodcolor(pro_id,type) {
            var res = "";
            for(var i=0;i<detail_data.length;i++)
            {
                if(detail_data[i][1]==pro_id && detail_data[i][2]==type && parseInt(detail_data[i][4])==0 )
                    res += "<li class='product_model produc_color' title="+pro_id+" id="+detail_data[i][0]+">"+detail_data[i][3]+"</li>";
            }
            return res;
        }
        function getGoodstock(pro_id,type) {
            for(var i=0;i<detail_data.length;i++)
            {
                if(detail_data[i][1]==pro_id && detail_data[i][2] == type){
                    return  "<span  class=' pro_stock_"+detail_data[i][1]+"' title="+detail_data[i][3]+"></span>";
                }
            }
        }
        function getGoodsval(pro_id,type) {
            for(var i=0;i<detail_data.length;i++)
            {
                if(detail_data[i][1]==pro_id && detail_data[i][2] == type){
                    return  "<span  class=' pro_price_"+detail_data[i][1]+"' title="+detail_data[i][3]+" ></span>";
                }
            }
        }
        function getTotalStock(id) {
            var total = 0;
            for(var i=0;i<detail_data.length;i++)
            {
                if(detail_data[i][1]==id && detail_data[i][2] == 'stock'){
                    total += parseInt(detail_data[i][3]) ;
                }
            }
            return total
        }
        $(document).on('click','.produc_color',function () {
            $('.produc_color').css('border','1px solid #bfbfbf');
            $(this).css('border','1px solid red');
            var pid =  $(this).attr('title');
            var id = $(this).attr('id');
            $('.hand_'+pid).hide();
            for(var i=0;i<detail_data.length;i++)
            {
                if(detail_data[i][4] == id && detail_data[i][2] == 'stock' && detail_data[i][1] == pid)
                {
                    $('.pro_stock_'+pid).text("数量:"+detail_data[i][3]);
                }
                if(detail_data[i][4] == id && detail_data[i][2] == 'price' && detail_data[i][1] == pid)
                {
                    $('.pro_price_'+pid).html("价格:<em>￥"+detail_data[i][3]+"</em>");
                }
            }
        });
    </script>
    <div class="wrap" id="#wrapper">
        <div class="main_list">
            <div class="other_list">
                @if($datas['products'])
                @foreach($datas['products'] as $list)
                <div class="store">
                    <div class="store_icon">
                        <img src="/img/00004.png" alt="" />
                        <span>{{ $brandName[$list->brand] }}</span>
                        <span style="float:right;color:#383838">所属：{{ $companys[$list->company_id] }}</span>
                    </div>
                    <div class="store_main">
                        <div class="storeDiv" id="{{ $list->id }}">
                            <div class="quan circle">
                                <img src="/img/00014.png"/>
                            </div>
                        </div>
                        <div class="store_pic">
                            <script>document.write("<img height='100%' width='100%' src='{{ env('CDN_DOMAIN_NAME') }}/upload/"+getGood('{{ $list->id }}','face')+"'/>");</script>
                        </div>
                        <div class="store_r">
                            <div class="storename">{{ $list->title }}</div>
                            <div class="productcolor">
                                <ul>
                                    <script>document.write(getGoodcolor('{{$list->id}}','color'));</script>
                                </ul>
                            </div>
                            <div class="store_id">款号:{{ $list->girard }}</div>
                            <span class="count_hand hand_{{$list->id}}">总手数：<script>document.write(getTotalStock('{{$list->id}}'));</script></span>
                            <div class="pro_sp">
                                <div class="pro_sum">
                                    <script>document.write(getGoodstock('{{$list->id}}','stock'));</script>
                                </div>
                                <div class="pro_price">
                                    <script>document.write(getGoodsval('{{$list->id}}','price'));</script>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="message">
                        <a class="message_a1" href="/produc/operationTool?good_id={{  $list->id }}">运营工具</a>
                        <a class="message_a2" href="/produc?good_id={{ $list->id }}">详细信息</a>
                    </div>
                </div>
                @endforeach
                @endif
            </div>
        <!--添加-->
            {{--加载--}}
            <div class="more" abc="">
                <div class="more_center">
                    <i class="pull_icon"></i><span>上拉加载...</span>
                </div>
            </div>
             <div class="uploading_over"></div>
        </div>
    </div>
    <div class="footer_box">
        <div class="footer">
            <div class="footer_l">
                <div class="arrows">
                    <img src="/img/00014.png" alt="" />
                </div>
                <span>全选</span>
            </div>
            <div class="footer_r">
                <input type="button" value="" class="del_inp footer_btn" />
                <input type="button" value="下架" class="down_inp footer_btn" />
            </div>
        </div>
    </div>
    <div class="del_success" style="display: none;">删除成功</div>
    <meta name="csrf_token" id="token" content="{{ csrf_token() }}">
</div>
</body>
<script>
    is_weixn('.footer_box');
    /*iphoneX*/
    var str= navigator.userAgent.toLowerCase();
    var ver=str.match(/cpu iphone os (.*?) like mac os/);
    if(ver && $(window).width() === 375 && $(window).height() === 724 && window.devicePixelRatio === 3){
        $(".footer_box").css("height","3.499rem");
        $(".wrap").css("bottom","3.499rem");
    }
    $(".see").click(function(){
        $(".see_img").css({"width":"13.5rem","float":"left"});
        $(".see_wrap").css({"marginLeft":"0.5rem","width":"12.9rem"});
        $(".see_name").css({"width":"12.3rem"});
        $(".see_name").removeAttr("disabled");
        $(".see_name").focus();
        $(".sousBtn").show();
    });
    /*点击键盘backspace键清空重复密码*/
    $('.see_name').keydown(function (event) {
        event=event||window.event;
        if (event.keyCode == 8) {
            if($('.see_name').val().length==1){
                $('.see_name').val("");
                window.location.href='/Business/producListRel';
            }
        }
    });
//    $(".see_name").blur(function(){
//        $(".see_img").css({"width":"100%"});
//        $(".see_wrap").css({"width":"2rem","margin":"0 auto"});
//        $(".see_name").css({"width":"1.3rem"});
//        $(".see_name").attr("disabled");
//        $(".sousBtn").hide();
//    });
    var kp = '{{ $datas['skip'] }}';
    $(".more").attr("abc",kp);
    /*滚动*/
    var myscroll = new iScroll("#wrapper",{
        onScrollMove:function(){
            if (this.y<(this.maxScrollY)) {
                $('.pull_icon').addClass('flip');
                $('.pull_icon').removeClass('loading');
                $('.more span').text('释放加载...');
            }else{
                $('.pull_icon').removeClass('flip loading');
                $('.more span').text('上拉加载...')
            }
        },
        onScrollEnd:function(){
            if ($('.pull_icon').hasClass('flip')) {
                $('.pull_icon').addClass('loading');
                $('.more span').text('加载中...');
                pullUpAction();
            }

        },
        onRefresh:function(){
            $('.more').removeClass('flip');
            $('.more span').text('上拉加载...');
        }
    });
    function pullUpAction(){
        var skip=$(".more").attr("abc");
        var girard=$(".see_name").val();
        $.ajax({
            url: '/apiGetProductInfo',
            type: 'post',
            headers: {'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')},
            data: {
                skip: skip,
                girard:girard
            },
            dataType: 'json',
            success: function (data) {
                if(data.success){
                    $(".more").attr("abc",data.info.skip);
                    var obj = Object.keys(data.info.products)
                    if(obj.length > 0){
                        var arr=data.info.products;
                        var path = '{{ env('CDN_DOMAIN_NAME') }}';
                        for(var i in arr){
                            if(data.info.type){
                                var types = '<span style="float:right;color:#383838;">所属：'+getcompany(arr[i].company_id)+'</span>'
                            }else{
                                var types = '';
                            }
                            var html='<div class="store">'+
                                        '<div class="store_icon">'+
                                            '<img src="/img/00004.png" alt="" />'+
                                            '<span>'+getbrandname(arr[i].brand)+'</span>' + types+ '</span>'+
                                        '</div>'+
                                        '<div class="store_main">'+
                                            '<div class="storeDiv" id='+arr[i].id+'>'+
                                                '<div class="quan circle">'+
                                                    '<img src="/img/00014.png"/>'+
                                                '</div>'+
                                            '</div>'+
                                            '<div class="store_pic">'+
                                                '<img height="100%" width="100%" src="'+path+'/upload/'+arr[i].face+'" />'+
                                            '</div>'+
                                            '<div class="store_r">'+
                                                '<div class="storename">'+arr[i].title+'</div>'+
                                                '<div class="productcolor">'+
                                                    '<ul>'+getGoodcolor(arr[i].id,'color')+'</ul>'+
                                                '</div>'+
                                                '<div class="store_id">款号:'+arr[i].girard+'</div>'+
                                                '<span class="count_hand hand_'+arr[i].id+'">总手数：'+getTotalStock(arr[i].id)+'</span>'+
                                                '<div class="pro_sp">'+
                                                    '<div class="pro_sum">'+getGoodstock(arr[i].id,'stock')+'</div>'+
                                                    '<div class="pro_price">'+getGoodsval(arr[i].id,'price')+'</div>'+
                                                '</div>'+
                                            '</div>'+
                                        '</div>'+
                                        '<div class="message">'+
                                            '<a class="message_a1" href="/produc/operationTool?good_id='+arr[i].id+'">运营工具</a>'+
                                            '<a class="message_a2" href="/produc?good_id='+arr[i].id+'">详细信息</a>'+
                                        '</div>'+
                                    '</div>';
                            $('.other_list').append(html)
                        }
                    }else{
                        $(".more_center").empty();
                        $(".more_center").text("我是有底线的");
                    }
                    myscroll.refresh();
                }else{

                }
            }
        });
    }
    if ($('.main_list').height()<$('.wrap').height()) {
        $('.more').hide();
        myscroll.destroy();
    }
/*已发布商品过多下面露出啦*/
//    if($(".store").length>=2){
//        $(".store").last().append("<p class='sky'></p>");
//    }
/*圈钩*/
    $(document).on('click','.circle',function () {
        if($(this).children('img').attr('src') == '/img/00014.png')
        {
            $(this).children('img').attr('src','/img/00012.png');
        }else{
            $(this).children('img').attr('src','/img/00014.png');
        }
    });
    $('.arrows').click(function () {
        if($(this).children('img').attr('src') == '/img/00014.png')
        {
            $(this).children('img').attr('src','/img/00012.png');

            $('.circle').children('img').attr('src','/img/00012.png');
        }else{
            $(this).children('img').attr('src','/img/00014.png');
            $('.circle').children('img').attr('src','/img/00014.png');
        }
    });
/*下架*/
    $('.down_inp').click(function () {
        var id = '';
        $('.circle').each(function () {
            if($(this).children('img').attr('src') == '/img/00012.png'){
                id += $(this).parent('.storeDiv').attr('id')+",";
                var date_id=$(this).parent('.storeDiv').attr('id');
                localStorage.setItem(date_id,"");
            }
        });
        if(id.length > 0)
        {
            $.ajax({
                url: '/Business/delProduct',
                type: 'POST',
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                },
                data: {id:id,status:0},
                dataType: 'json',
                success: function (data) {
                    if (data.success == true) {
                        $('.circle').each(function () {
                            if($(this).children('img').attr('src') == '/img/00012.png')
                                $(this).parent().parent().parent('.store').remove();
                        });
                        $('.arrows img').attr('src','/img/00014.png');
                        usermsg('下架成功');
                    } else {
                        usermsg(data.msg)
                    }
                }
            })
        }else{
            usermsg('请勾选要下架的商品')
        }
    });
/*颜色选择*/
    $(document).on('click','.produc_color',function () {
        $(this).css({"background":"#ea294b","color":"#fff"})
        $(this).siblings().css({"background":"#e9e9e9","color":"#383838"})
    });
/*弹出框提示*/
    function usermsg(msg) {
        $('.del_success').text(msg);
        $('.del_success').show(0).delay(1000).hide(0);
    }
/*剩余总数*/
//    var count_num=0;
//    var arr=[];
//    for(var k=0;k<detail_data.length;k++){
//        if(detail_data[k][2]=='stock'){
//            if(arr[detail_data[k][1]]){
//                arr[detail_data[k][1]] = parseInt(arr[detail_data[k][1]]) + parseInt(detail_data[k][3]) ;
//            }else{
//                arr[detail_data[k][1]] = parseInt(detail_data[k][3]);
//            }
//        }
//    }
//    for (var i in arr){
//        $(".hand_"+i).text("总手数："+arr[i]);
//    }
</script>
</html>
